#include "ObCoinUp.h"
#include "Collision.h"

ObCoinUp::ObCoinUp(IDirect3DTexture9* mtex, float px, float py, float vx, float vy, float time){
	mID		= 0;
	mInfo	= 0;
	mWidth	= 16.0f;
	mHeight = 16.0f;
	mCenter = D3DXVECTOR3(mWidth/2, mHeight/2, 0.0f);
	mSpritePos.x = 10;
	mSpritePos.y = 8;

	mNeedCollision = false;
	mTex = mtex;
	mPos.x = px;
	mPos.y = py;
	mVelocity.x = vx;
	mVelocity.y = vy;
	mTime = time;
	mCurrentSprite = 0;
	
	mIsXGravity = false;
	mIsYGravity = true;
	
	MAX_VELOCITYX = 0;
	MAX_VELOCITYY = 500;
}

void ObCoinUp::update(float dt){
	if(mNeedDispose) return;
	if(mTime>0.0f){
		mTime -=dt;
		if(mTime <=0.0f){
			mNeedDispose = true;
			mTime = true;
			return;
		}
		updateMoving(dt, dt, dt);
	}
}

void ObCoinUp::render(ID3DXSprite* mSprite){
	if(mNeedDispose) return;

	HR(gDevice->SetRenderState(D3DRS_ALPHATESTENABLE,true));
	D3DXMATRIX S;
	D3DXMatrixScaling(&S,1.0f,-1.0f,1.0f);
	D3DXMATRIX R;
	D3DXMatrixRotationZ(&R, mRotation);
	D3DXMATRIX T;
	D3DXMatrixTranslation(&T,mPos.x - gCamera->getPos().x, mPos.y - gCamera->getPos().y, 0);
	mSprite->SetTransform(&(S*R*T));
	RECT rect = calRenderRECT(mSpritePos,mWidth,mHeight);
	mSprite->Draw(mTex,&rect,&mCenter,0,D3DCOLOR_XRGB(255, 255, 255));
	mSprite->Flush();
	HR(gDevice->SetRenderState(D3DRS_ALPHATESTENABLE,false));
}

void ObCoinUp::clear(){
	mTex = NULL;
}
